package com.xiaoge.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaoge.annotation.ControllerEndpoint;
import com.xiaoge.entity.EduAdv;
import com.xiaoge.response.Result;
import com.xiaoge.service.EduAdvService;
import com.xiaoge.vo.EduAdvVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.text.ParseException;

/**
 *@作者: 冷俊杰
 *@类名: EduAdvController类
 *@创建时间: 2022/11/9 21:09
 *@描述:
 *广告信息(轮播管理)
 *@修改原图
 *@修改作者
 *@修改时间
 */
@Api(value = "轮播管理", tags = "轮播管理")
@RestController
@RequestMapping("/eduAdv")
public class EduAdvController {
    @Resource
    private EduAdvService eduAdvService;

    @ControllerEndpoint(exceptionMessage = "删除轮播失败", operation = "删除轮播")
    @RequiresPermissions({"eduCourse:DeEduAdv"})
    @ApiOperation(value = "删除轮播", notes = "删除轮播信息，根据轮播ID")
    @DeleteMapping("DeEduAdv")
    public Result DeEduAdv(@RequestParam(value = "id",required = true,defaultValue = "")Long id){
        eduAdvService.removeById(id);
        return Result.ok();
    }

    @ControllerEndpoint(exceptionMessage = "修改轮播失败", operation = "修改轮播")
    @RequiresPermissions({"eduCourse:UpEduAdv"})
    @ApiOperation(value = "修改轮播", notes = "修改轮播信息，根据轮播ID")
    @PutMapping("UpEduAdv")
    public Result UpEduAdv(EduAdvVO vo){
        eduAdvService.UpEduAdv(vo);
        return Result.ok();
    }

    @ControllerEndpoint(exceptionMessage = "添加轮播失败", operation = "添加轮播")
    @RequiresPermissions({"eduCourse:InEduAdv"})
    @ApiOperation(value = "添加轮播", notes = "添加轮播信息")
    @PostMapping("InEduAdv")
    public Result InEduAdv(EduAdvVO vo, MultipartFile file) throws ParseException {
        eduAdvService.InEduAdv(vo,file);
        return Result.ok();
    }

    @ControllerEndpoint(exceptionMessage = "查询轮播失败", operation = "查询轮播")
    @ApiOperation(value = "查询轮播", notes = "查询轮播")
    @PostMapping("getEduAdvByPage")
    public Result getEduAdvByPage( @RequestParam(value = "current",required = true,defaultValue = "1") Integer current,
                                   @RequestParam(value = "size",required = true,defaultValue = "7") Integer size){
        Page<EduAdv> page = new Page<>(current,size);
        Page<EduAdv> eduAdvByPage = eduAdvService.getEduAdvByPage(page);
        return Result.ok().data("eduAdvByPage",eduAdvByPage);
    }

}
